package cn.neusoft.controller;


import cn.neusoft.po.Dicdetail;
import cn.neusoft.query.DicdetailQuery;
import cn.neusoft.service.IDicdetailService;
import cn.neusoft.vo.ResponseObj;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hxj
 * @since 2023-12-25
 */
@RestController
@RequestMapping("/dicdetail")
public class DicdetailController {

    @Autowired
    IDicdetailService service;

    @PostMapping
    public ResponseObj saveOrUpdate(@RequestBody Dicdetail dicdetail){
        boolean b = service.saveOrUpdate(dicdetail);
        return b?ResponseObj.SUCCESS():ResponseObj.ERROR(10001,"保存部门信息失败");
    }

    @DeleteMapping("/{id}")
    public ResponseObj delete(@PathVariable("id") Integer id){
        boolean b = service.removeById(id);
        return b?ResponseObj.SUCCESS():ResponseObj.ERROR(10002,"删除部门信息失败");
    }

    @GetMapping("/{id}")
    public ResponseObj getById(@PathVariable("id") Integer id){
        Dicdetail dicdetail = service.getById(id);
        return ResponseObj.SUCCESS(dicdetail);
    }

    @PostMapping("/page")
    public ResponseObj getByPage(@RequestBody DicdetailQuery query){
        Page<Dicdetail> page = service.getByPage(query);
        return ResponseObj.SUCCESS(page);
    }

    @GetMapping("/all")
    public ResponseObj getAll(){
        List<Dicdetail> list = service.list();
        return ResponseObj.SUCCESS(list);
    }

    @GetMapping("/getByType/{sn}")
    public ResponseObj getByTypes(@PathVariable("sn") String sn){
        List<Dicdetail> types = service.getByTypes(sn);
        return ResponseObj.SUCCESS(types);
    }
    
}
